module manager {

    export class UtilsManager {

        public static getTimeFormatByNum(num: number, type: string = ":", showNum: number = 3): string {
            let s: string;
            let hour: string;
            let minute: string;
            let second: string;
            if (showNum == 1) {
                second = this.numberFormat(num);
                return second;
            } else if (showNum == 2) {
                minute = this.numberFormat((num / 60));
                second = this.numberFormat(num % 60);
                return minute + type + second;
            } else {
                hour = this.numberFormat(num / 60 / 60 >> 0);
                minute = this.numberFormat((num / 60) % 60);
                second = this.numberFormat(num % 60);
                return hour + type + minute + type + second;
            }
        }

        public static getYearMonthDayNumber(): number {
            let today = new Date();
            let format = today.getFullYear().toString();
            let month = today.getMonth();
            if (month < 10) {
                format = format + "0" + month;
            } else {
                format = format + month;
            }

            let day = today.getDate();
            if (day < 10) {
                format = format + "0" + day;
            } else {
                format = format + day;
            }
            egret.log("当前时间数字:", format);
            return parseInt(format);
        }

        public static numberFormat(num: number): string {
            num = Math.floor(num);
            if (num >= 10) return "" + num;
            else return "0" + num;
        }

        public static getYearMonthDay(): string {
            let ret: string = "";
            let date: Date = new Date();
            let year: number = date.getFullYear();
            let month: number = date.getMonth();
            let day: number = date.getDate();
            ret = ret + year;
            if (month < 10) {
                ret = ret + "0" + month;
            } else {
                ret = ret + month;
            }
            if (day < 10) {
                ret = ret + "0" + day;
            } else {
                ret = ret + day;
            }
            return ret;
        }

        public static twoDistance(a: any, b: any): number {
            let x: number = a.x - b.x;
            let y: number = a.y - b.y;
            return Math.sqrt(x * x + y * y);
        }

        public static getRect(w: number, h: number, c: number = 0, x: number = 0, y: number = 0): egret.Sprite {
            let s: egret.Sprite = new egret.Sprite()
            s.graphics.beginFill(c);
            s.graphics.drawRect(x, y, w, h);
            s.graphics.endFill();
            return s;
        }


        public static sqrt(x: number, y: number): number {
            return Math.sqrt(x * x + y * y);
        }

        public static setStore(key: string, data: any): void {
            wx.setStorage({
                key: key,
                data: data,
                success: function (res) {
                },
                fail: function (res) {
                },
                complete: function (res) {
                }
            });
        }

    }

}